//
//  WaypointsTableViewCell.m
//  HappinessTrip
//
//  Created by dllo on 15/10/16.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "WaypointsTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Fit.h"

@implementation WaypointsTableViewCell



-(void)dealloc
{
    [_topImageView release];
    [_indexLabel release];
    [_iconImageView release];
    [_timeLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}
-(void)createViews
{
    _topImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_topImageView];
    [_topImageView release];
    _indexLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_indexLabel];
    [_indexLabel release];
    _iconImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_iconImageView];
    [_iconImageView release];
    _timeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_timeLabel];
    [_timeLabel release];
    
}

-(void)setPhoto_info:(NSDictionary *)photo_info
{
    CGFloat width = [[photo_info objectForKey:@"w"]floatValue];
    CGFloat height = [[photo_info objectForKey:@"h"]floatValue];
    CGFloat bili = width / 335 * W;
    if (bili != 0) {
        CGFloat imageHeight = height / bili;
        _topImageView.frame = CGRectMake(20 * W, 10 * H, 335 * W, imageHeight);
    }
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], NSFontAttributeName, nil];
    CGRect rect = [_point.text boundingRectWithSize:CGSizeMake(335 * W, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    _indexLabel.frame = CGRectMake(_topImageView.frame.origin.x , _topImageView.frame.origin.y + _topImageView.frame.size.height + 10 * H, _topImageView.frame.size.width, rect.size.height);
    _iconImageView.frame = CGRectMake(_indexLabel.frame.origin.x, _indexLabel.frame.origin.y + _indexLabel.frame.size.height + 10 * H, 20 * W, 20 * H);
    _timeLabel.frame = CGRectMake(_iconImageView.frame.origin.x + _iconImageView.frame.size.width + 10 * W, _iconImageView.frame.origin.y, _indexLabel.frame.size.width - _iconImageView.frame.size.width, _iconImageView.frame.size.height);

}

-(void)setPoint:(Waypoints *)point
{
    if (_point != point) {
        [_point release];
        _point = [point retain];
    }

    [_topImageView sd_setImageWithURL:[NSURL URLWithString:_point.photo] placeholderImage:[UIImage imageNamed:@"dengdai"]];
    _topImageView.layer.cornerRadius = 10;
    _topImageView.layer.masksToBounds = YES;
    _indexLabel.text = _point.text;
    _indexLabel.numberOfLines = 0;
    _iconImageView.image = [UIImage imageNamed:@"shizhong"];
    _timeLabel.text = _point.local_time;
}













- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
